package levelSystem;

import java.awt.event.KeyEvent;

public abstract class KeyProcessor {
	
	private GameLevel owner;
	
	private boolean f3Pressed;
	
	public KeyProcessor(GameLevel o) {
		owner = o;
		
		f3Pressed = false;
	}
	
	public void processKey(KeyEvent e, int type)
    {
        switch(type)
            {
                case 1:
                    switch(e.getKeyCode())
                    {
                        /* Direcionais */
                        case KeyEvent.VK_UP:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                            owner.procUp(1);
                            break;
                        case KeyEvent.VK_DOWN:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procDown(1);
                            break;
                        case KeyEvent.VK_LEFT:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procLeft(1);
                            break;
                        case KeyEvent.VK_RIGHT:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procRight(1);
                            break;
                        
                        /* ASDW enter */
                        case KeyEvent.VK_A:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procA(1);
                            break;
                        case KeyEvent.VK_S:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procS(1);
                            break;
                        case KeyEvent.VK_D:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procD(1);
                            break;
                        case KeyEvent.VK_W:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procW(1);
                            break;
                        case KeyEvent.VK_ENTER:
                        	if(!owner.isChangingLevel())
                        	owner.procEnter(1);
                            break;
                        
                        /* Debug */
                        case KeyEvent.VK_F3:
                        	if(!f3Pressed)
                        	{
                        		f3Pressed = true;
                        		owner.debugSwitch();
                        	}
                        	break;
                        	
                        case KeyEvent.VK_SPACE:
                        	if(owner.isPaused()) owner.resumeGame();
                        	else if(owner.canPause())owner.pauseGame();
                        	break;
                    }
                    break;
                case 2:
                	switch(e.getKeyCode())
                    {
                        /* Direcionais */
                        case KeyEvent.VK_UP:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                            owner.procUp(2);
                            break;
                        case KeyEvent.VK_DOWN:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procDown(2);
                            break;
                        case KeyEvent.VK_LEFT:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procLeft(2);
                            break;
                        case KeyEvent.VK_RIGHT:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procRight(2);
                            break;
                        
                        /* ASDW enter */
                        case KeyEvent.VK_A:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procA(2);
                            break;
                        case KeyEvent.VK_S:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procS(2);
                            break;
                        case KeyEvent.VK_D:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procD(2);
                            break;
                        case KeyEvent.VK_W:
                        	if(!owner.isPaused() && !owner.isChangingLevel())
                        	owner.procW(2);
                            break;
                        case KeyEvent.VK_ENTER:
                        	owner.procEnter(2);
                            break;
                        
                        /* Debug */
                        case KeyEvent.VK_F3:
                        	f3Pressed = false;
                        	break;
                        	
                        /* Game Over */
                        case KeyEvent.VK_ESCAPE:
                        	if(owner.isGameOver() && !owner.retryed())
                        	{
                        		owner.setFadeOutComponents();
                        		owner.activateLevelChange();
                        	}
                        	break;
                        	
                        case KeyEvent.VK_R:
                        	if(owner.isGameOver() && !owner.returned())
                        	{
                        		owner.setFadeOutComponents();
                        		owner.retry();
                        	}
                        	break;
                    }
                	break;
            }
    }
}
